<?php

$fileName = @$_REQUEST["fileName"];
$id = @$_REQUEST["id"];
$mode = @$_REQUEST["mode"];

if ($mode == "attachment")
	$fileString = __DIR__ . "/service/attachments/$id";
else
	$fileString = __DIR__ . "/service/files/$id";

if (file_exists($fileString))
{
	header("Cache-Control: ");
	header("Pragma: ");
	header("Content-type: application/octet-stream");
	header("Content-Disposition: attachment; filename=\"". $fileName . "\"");
	header("Content-length:".(string)(filesize($fileString)));
	sleep(1);
	readfile($fileString);
}
else
	echo("File not found");
?>